/**
 * 
 */
package cn.agiledata.bank.audit.logic;

import cn.agiledata.bank.hibernateBean.AuditRule;
import cn.agiledata.bank.hibernateBean.AuditStep;

/**
 * @author 马贤波
 * 
 */
public final class AuditRuleWrapper {
    private AuditRule auditRule;

    public AuditRuleWrapper(AuditRule auditRule) {
        this.auditRule = auditRule;
    }

    public AuditRule getAuditRule() {
        return this.auditRule;
    }

    public AuditStep[] getAuditSteps() {
        return (AuditStep[]) this.getAuditRule().getAuditSteps().toArray(
                new AuditStep[0]);
    }

    public AuditStep getLastAuditStep() {
        AuditStep[] auditSteps = this.getAuditSteps();
        return auditSteps.length == 0 ? null
                : auditSteps[auditSteps.length - 1];
    }

    public AuditLevel maxAuditLevel() {
        AuditStep lastAuditStep = this.getLastAuditStep();
        if (lastAuditStep == null)
            return AuditLevel.LEVEL_PRIMARY;
        return AuditLevel.getAuditLevel(lastAuditStep.getLevel());
    }
}
